In the last part we found out that our customized healthcare sector index showed that the second highest
chop ratio and we presented this to our client Mary.
However the results of Part 5 supported Mary's belief that the health care sector is the one and only
sector to be invested in.
And she says even if the consumer services sector showed a better Sharpe ratio and a higher return than
the healthcare sector the risk is simply too high and that there's no benefit to add other sectors with
lower Sharpe ratio than the healthcare sector.
Because this will not improve the shop ratio of the overall portfolio and therefore I will stick to
my current stock portfolio.
So that's the marriage statement here and our argument.
Past performance is no guarantee or no indicator of future results did not impress her much and I mean
Mary's arguments are reasonable for a person who is not an expert in finance and investments but they
are nevertheless wrong because they do not take into account the portfolio diversification effect and
that means that by creating a portfolio with many sectors we can reduce the sector specific risk not
only for the healthcare sector but also for the other sectors.
And that's why there still a good chance to find portfolios that so a better Sharpe ratio with the same
or lower risk than the health care sector on a standalone basis.
And our client Mary might not be an easy person but she is definitely open to a reasonable and well-founded
arguments and therefore we will create 50000 random portfolios and show her that she could have done
even better with a higher degree of diversification in her portfolio.
All right let's stop coding here and we have still important here.
Our returns state frame with the daily returns of the sectors here and in total we have 11 sectors or
eleven assets and we tried to simulate 50000 random portfolios number of portfolios.
And then on the next step we create the fifty thousand times eleven the random numbers between 0 and
1 and we reshape them in two or fifty thousand rows and eleven columns and we save them in the variable
matrix and we set to the random C 2 1 1 1.
So this shows actually a reproducibility here and let's do this and then we transform our random numbers
into weights where for each and every of the 50000 portfolios the weights of the constituent sum up
to 1.
And we save the weights matrix and the variable weights so here we have fifty thousand portfolios with
eleven constituents and we can also have a look here at the very first portfolios.
So here is one portfolio with a 13 percent for the very first asset and so on and having the daily returns
of the eleven constituents and the random weights we can actually create the daily returns of our fifty
thousand random portfolios by using here the top method and actually we are performing a matrix multiplication
and uh we save um the daily returns of the fifty thousand portfolios and the variable part read and
let's have a look here.
So here we have fifty thousand columns and fifty thousand portfolios then in the next set we can calculate
the annualized the risk and return for those portfolios by simply passing our data frame portfolio returns
to our user defined function annualized the risk and return and be safe.
The summary here and the variable portfolio summary.
So this is the most time consuming step here
and let's have a look at the portfolio summary data frame so here we have uh the annualized the return
and the annualized risk for fifty thousand random portfolios.
And then the next step we can visualize the fifty thousand portfolios in a total risk return framework
and again we are creating the scatter plot twists on the x axis the risk column and on the y axis the
return column.
And we also plot our 11 indexes.
So let's have a look here.
And that's actually our cloud of potential portfolios.
And here we have the efficient frontier.
And this is near our healthcare index and at a first glance we can see that there are indeed portfolios
that have actually the same risk.
Yes our healthcare index on a standalone basis but deliver more return.
So here and are even portfolios that have less risk and at least the same return as our health care
index.
So here for example and finally we can also calculate the SAP ratio for our 50000 portfolios.
So we are creating the additional column sharp and that's our portfolio summary data frame with the
addition column sharp and we can also call the scribe method here and here we can see that the maximum
Sharpe ratio is one point fourteen one and then we can also get the index label of the max swap rates
for portfolio with the idea X Max method
and the index label of the max Sharpe ratio is the forty six thousand nine hundred fifty seven and we
can also select a complete row with our Max Sharpe Ratio portfolio and here we have a return of 17 percent
and they risk off thirteen point seven percent resulting in a sharp ratio of one point fourteen and
let's compare this also to our health care index and here we had a return of about 14 percent and a
risk of fourteen point three percent.
So the max Sharpe Ratio portfolio delivered actually a lower risk and higher return.
And of course then also a higher Sharpe ratio.
And last but not least we can also get the rates of the constituents and the max Sharpe Ratio portfolio.
So let's also create a pen a serious and we can see that we have in the MAX Sharpe Ratio portfolio high
rates of the health care index.
So that's no surprise.
And also of the Consumer Services Index and actually finally we presented our results to marry and showed
her the portfolio diversification effect.
And uh finally we could manage to convince Mary to diversify her stock portfolio so for the future she
will also add some more sectors to her health care portfolio.
And we will do this in the very last step Step 7.
And I hope to see you there by.